import DogConfig from "../data/DogConfig";
import OperateData from "../game/OperateData";
import UserData from "../game/UserData";
import Kits from "../kit/Kits";

const { ccclass, property } = cc._decorator;

export default class UserDogModel {

    public fields: Array<string> = ['_age', '_sex', '_name', '_happiness', '_healthy', '_cute', '_love', '_species'];

    private _age = 0;
    private _sex = 0;
    private _name = "鸡蛋";
    private _happiness = 0.5;
    private _healthy = 0.5;
    private _cute = 0.5;
    private _love = 0.5;
    private _species = 1;   //物种 

    constructor(data) {
        if (data) {
            //todo
        } else {
            //todo
            this.randomName();
            this.randomSpecies();
        }
    }

    public addAge() {
        this._age += 3;


    }

    public updateEvent(age) {

        let eventItem = OperateData.getRecordEventItemByAge(age);
        let index = UserData.getInstance().chooseRecord[age].index;

        let behaviorList = eventItem.behaviorList;

        let behaviorItem = behaviorList[index];

        this._happiness += behaviorItem.effect[0] / 100;
        this._healthy += behaviorItem.effect[1] / 100;
        this._cute += behaviorItem.effect[2] / 100;
        this._love += behaviorItem.effect[3] / 100;

        this.checkData();
    }

    public checkData() {
        this._happiness = this._happiness > 1 ? 1 : this._happiness;
        this._happiness = this._happiness < 0 ? 0 : this._happiness;

        this._healthy = this._healthy > 1 ? 1 : this._healthy;
        this._healthy = this._healthy < 0 ? 0 : this._healthy;

        this._cute = this._cute > 1 ? 1 : this._cute;
        this._cute = this._cute < 0 ? 0 : this._cute;

        this._love = this._love > 1 ? 1 : this._love;
        this._love = this._love < 0 ? 0 : this._love;

    }

    //随机名字
    public randomName() {
        let data = DogConfig.data;
        let attribute = Kits.randomAttribute(data);
        this._name = attribute.name;
    }

    //随机种族
    public randomSpecies() {
        let data = DogConfig.data;
        let count = Kits.attributeCount(data);
        this._species = Kits.randomInter(1, count + 1);
    }

    get age() {
        return this._age;
    }
    get sex() {
        return this._sex;
    }
    get name() {
        return this._name;
    }
    get happiness() {
        return this._happiness;
    }
    get healthy() {
        return this._healthy;
    }
    get cute() {
        return this._cute;
    }
    get love() {
        return this._love;
    }
    get species() {
        return this._species;
    }
}
